package com.example.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.auth.service.ItripUserService;
import org.example.mapper.ItripUserMapper;
import org.example.pojo.ItripUser;
import org.example.utils.RandomUUID;
import org.example.utils.TimeD;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.Date;


@Service
public class ItripUserServiceImpl implements ItripUserService {
    @Autowired
    private ItripUserMapper itripUserMapper;
    private QueryWrapper<ItripUser> queryWrapper;

    @Override
    public int insertUser(ItripUser itripUser) {
        itripUser.setCreationDate(TimeD.StringByDate(RandomUUID.NowTimeByS()));
        itripUser.setUserType(0);itripUser.setFlatID(1L);itripUser.setUserName("User"+RandomUUID.generatorUUID());
        return itripUserMapper.insert(itripUser);
    }

    @Override
    public boolean loginByPwd(String phone, String pwd) {
        queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userCode",phone).eq("userPassword",pwd);
        if (itripUserMapper.selectOne(queryWrapper)!=null)
            return true;
        else
            return false;
    }

    @Override
    public ItripUser existsUser(String phone){
        queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userCode",phone);
        return itripUserMapper.selectOne(queryWrapper);
    }
}
